package sjq.com.time.util;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by hechuan on 2016/6/21.
 */
public abstract class CommandAdapter<T>  extends RecyclerView.Adapter<ViewHolder>{
    Context context;
    int layoutId;
    List<T> datas;

    public CommandAdapter(Context context,int layoutId,List<T> datas){
        this.context = context;
        this.layoutId =layoutId;
        this.datas =datas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return ViewHolder.get(context,layoutId,parent);

    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        convert(holder,datas.get(position),position);
    }

    @Override
    public int getItemCount() {
        return datas == null? 0 : datas.size();
    }

    /**
     * 处理真实的数据
     */
    protected abstract void convert(ViewHolder holder, T t, int position);

}
